﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using iTextSharp.text.pdf;

namespace PdfObjectInjection
{
    public class PdfInject
    {
        public List<string> ItemNotFoundCollection { get; set; }

        public PdfInject(object currentForm, AcroFields fields)
        {
            var type = currentForm.GetType();
            var properties = type.GetProperties().ToList();
            ItemNotFoundCollection = new List<string>();

            properties.ForEach(delegate (PropertyInfo info)
                                   {
                                       string infoValue = info.GetValue(currentForm, null) as string;

                                       if( !String.IsNullOrEmpty(infoValue) && fields.Fields.ContainsKey(info.Name))
                                           fields.SetField(info.Name, info.GetValue(currentForm, null).ToString());
                                       else
                                           ItemNotFoundCollection.Add(info.Name);
                                   });
        }


        public bool ItemNotFound
        {
            get { return ItemNotFoundCollection.Count > 0; }
        }
    }}
